package com.donfu.web.controller.house;

import java.util.List;
import java.util.Map;

import com.donfu.system.domain.house.HouseNovelty;
import com.donfu.system.domain.house.HouseOrder;
import com.donfu.system.domain.house.HouseOrderGoods;
import com.donfu.system.service.house.IHouseOrderGoodsService;
import com.donfu.system.service.house.IHouseOrderService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.donfu.common.annotation.Log;
import com.donfu.common.core.controller.BaseController;
import com.donfu.common.core.domain.AjaxResult;
import com.donfu.common.enums.BusinessType;
import com.donfu.common.utils.poi.ExcelUtil;
import com.donfu.common.core.page.TableDataInfo;

/**
 * 订单信息Controller
 * 
 * @author donfu
 * @date 2021-12-06
 */
@RestController
@RequestMapping("/house/order")
public class HouseOrderController extends BaseController
{
    @Autowired
    private IHouseOrderService houseOrderService;

    @Autowired
    private IHouseOrderGoodsService houseOrderGoodsService;


    //@PreAuthorize("@ss.hasPermi('house:novelty:list')")
    @ApiOperation("列表查询")
    @GetMapping("/list")
    public TableDataInfo list(Integer orderStatus)
    {
        startPage();
        List<Map<String, String>> list = houseOrderService.getOrderInfo(orderStatus);
        return getDataTable(list);
    }

    @PostMapping("/updateStatus")
    public AjaxResult updateOrderStatus(@RequestParam(name = "id")  Long id, @RequestParam(name = "orderStatus") Integer orderStatus){
        HouseOrder houseOrder = new HouseOrder();
        houseOrder.setId(id);
        houseOrder.setOrderStatus(orderStatus);
        houseOrderService.updateHouseOrder(houseOrder);
        return AjaxResult.success("订单修改成功！");
    }
    @PostMapping("/updateNote")
    public AjaxResult updateOrderStatus(@RequestParam(name = "id")  Long id, @RequestParam(name = "adminMsg") String adminMsg){
        HouseOrder houseOrder = new HouseOrder();
        houseOrder.setId(id);
        houseOrder.setAdminMsg(adminMsg);
        houseOrderService.updateHouseOrder(houseOrder);
        return AjaxResult.success("订单修改成功！");
    }
    /*
    * @作者 覃创斌
    * @描述 查询商品详情
    * @日期 2021/12/9
    **/
    @PostMapping("/getOrderGoodsDetails")
    public AjaxResult getOrderGoodsDetails(@RequestBody HouseOrderGoods houseOrderGoods){
        Map<String, String> list = houseOrderService.getOrderDetails(houseOrderGoods.getId());

        List<HouseOrderGoods> houseOrderGoodsList = houseOrderGoodsService.selectHouseOrderGoodsList(houseOrderGoods);
        return AjaxResult.success().put("Order",list).put("OrderGoods",houseOrderGoodsList);
    }
}
